//
//  AppConfig.swift
//  GenericProjectForSwift
//
//  Created by 漠然丶情到深处 on 2019/12/21.
//  Copyright © 2019 漠然丶情到深处. All rights reserved.
//

import UIKit


/****************************************************颜色****************************************************/
/**
 * 颜色
 */
func LS_kRGBAColor(r: CGFloat,_ g: CGFloat,_ b: CGFloat,_ a: CGFloat) -> UIColor {
    return UIColor(red: (r)/255.0, green: (g)/255.0, blue: (b)/255.0, alpha: (a))
}
func LS_RGBAColor(r: CGFloat,_ g: CGFloat,_ b: CGFloat,_ a: CGFloat) -> UIColor {
    return UIColor(red: (r), green: (g), blue: (b), alpha: (a))
}
/**
 * 页面底色
 */
let LSViewBackgroundColor = LS_kRGBAColor(r: 242.0, 242.0, 242.0, 1)
/**
 * rgb颜色转换（16进制->10进制）
 */
func LSColorFromRGB(rgbValue: CGFloat) -> UIColor {
    return UIColor(red: ((CGFloat)((Int(rgbValue) & 0xFF0000) >> 16))/255.0, green: ((CGFloat)((Int(rgbValue) & 0xFF00) >> 8))/255.0, blue: ((CGFloat)(Int(rgbValue) & 0xFF))/255.0, alpha: 1.0)
}
let LSClearColor = UIColor.clear
let LSWhiteColor = UIColor.white
let LSBlackColor = UIColor.black
let LSGrayColor = UIColor.gray
let LSBlueColor = UIColor.blue
let LSRedColor = UIColor.red
let LSCyanColor = UIColor.cyan
let LSYellowColor = UIColor.yellow
let LSOrangeColor = UIColor.orange
let LSPurpleColor = UIColor.purple
let LSBrownColor = UIColor.brown
let LSGreenColor = UIColor.green
let LSMagentaColor = UIColor.magenta
let LSDarkGrayColor = UIColor.darkGray
let LSLightGrayColor = UIColor.lightGray
//字体
func LSSystemFont(NAME:String, FONTSIZE: CGFloat) -> UIFont {
    return UIFont(name: String(format: "PingFangSC-%@", NAME), size: FONTSIZE)!
}
//定义UIImage对象
func LSImageNamed(name: String) -> UIImage {
    return UIImage.init(named: name)!
}

/**************************************************屏幕适配**************************************************/
/**
 * 屏幕宽和高
 */
let LSScreenWidth = UIScreen.main.bounds.size.width
let LSScreenHeight = UIScreen.main.bounds.size.height
let LSScreenBounds = UIScreen.main.bounds
//判断横屏还是竖屏
let LSIsPortrait = UIApplication.shared.statusBarOrientation == UIInterfaceOrientation.portrait || UIApplication.shared.statusBarOrientation == UIInterfaceOrientation.portraitUpsideDown
// 判断是否为iPhone
let LS_IS_IPHONE = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.phone)
// 判断是否为iPad
let LS_IS_IPAD = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad)
//iPhone与iPad适配
func LSSYRealValue(value1: CGFloat, value2: CGFloat) -> CGFloat {
    return LS_IS_IPHONE == true ? ((value1) / 375.0 * LSScreenWidth) : ((value2) / 1024.0 * LSScreenWidth)
}

//----------------判断系统版本---------------
// 获取系统版本
let IOS_SYSTEM_VERSION = Double(UIDevice.current.systemVersion)

/// 顶部安全区高度
func LSSafeDistanceTop() -> CGFloat {
    if #available(iOS 13.0, *) {
        let scene = UIApplication.shared.connectedScenes.first
        guard let windowScene = scene as? UIWindowScene else { return 0 }
        guard let window = windowScene.windows.first else { return 0 }
        return window.safeAreaInsets.top
    } else if #available(iOS 11.0, *) {
        guard let window = UIApplication.shared.windows.first else { return 0 }
        return window.safeAreaInsets.top
    }
    return 0;
}

/// 底部安全区高度
func LSSafeDistanceBottom() -> CGFloat {
    if #available(iOS 13.0, *) {
        let scene = UIApplication.shared.connectedScenes.first
        guard let windowScene = scene as? UIWindowScene else { return 0 }
        guard let window = windowScene.windows.first else { return 0 }
        return window.safeAreaInsets.bottom
    } else if #available(iOS 11.0, *) {
        guard let window = UIApplication.shared.windows.first else { return 0 }
        return window.safeAreaInsets.bottom
    }
    return 0;
}

/// 顶部状态栏高度（包括安全区）
func LSSTATUS_BAR_HEIGHT() -> CGFloat {
    var statusBarHeight: CGFloat = 0
    if #available(iOS 13.0, *) {
        let scene = UIApplication.shared.connectedScenes.first
        guard let windowScene = scene as? UIWindowScene else { return 0 }
        guard let statusBarManager = windowScene.statusBarManager else { return 0 }
        statusBarHeight = statusBarManager.statusBarFrame.height
    } else {
        statusBarHeight = UIApplication.shared.statusBarFrame.height
    }
    return statusBarHeight
}

/// 导航栏高度
func LSNAVIGATION_BAR_HEIGHT() -> CGFloat {
    return LS_IS_IPHONE == true ?  44.0 : 72.0
}

/// 状态栏+导航栏的高度
func LSNAVIGATION_STATUS_HEIGHT() -> CGFloat {
    return LSSTATUS_BAR_HEIGHT() + LSNAVIGATION_BAR_HEIGHT()
}

/// 底部导航栏高度
func LSTAB_BAR_HEIGHT() -> CGFloat {
    return 49.0
}

/// 底部导航栏高度（包括安全区）
func LSTAB_HOME_HEIGHT() -> CGFloat {
    return LSTAB_BAR_HEIGHT() + LSSafeDistanceBottom()
}
///***********************************************************************************************************/
